package com.complex.spring.advance.service.context;

import java.util.Properties;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.complex.spring.advance.service.ITestC;

public class TestApplicationContext {
	public static void main(String[] args) {
		//通过ClassPathXmlApplicationContext  默认从classpath下查找
		//ApplicationContext 同时具备ResourceLoader和BeanFactory的功能
		/**
		 * BeanFactory xmlbean = new XmlBeanFactory(new ClassPathResource(
				"/bean/spring-service.xml"));
				比较可以看出,BeanFactory则没有ResourceLoader的能力
		 */
		System.out.println("ApplicationContext ==>");
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:bean/spring-service.xml");
		context.getBean("testC");
		
		ITestC testC = (ITestC) context.getBean("testC");
		testC.print();
		System.out.println("FileSystemXmlApplicationContext ==>");
		//FileSystemXmlApplicationContext 默认从文件系统中查找,当指定classpath时,也能从classpath下查找
		context = new FileSystemXmlApplicationContext("classpath:bean/spring-service.xml");
		testC = (ITestC) context.getBean("testC");
		testC.print();
		
		System.out.println("propertiesLoader ==>");
		TestPropertiesLoader propertiesLoader = (TestPropertiesLoader) context.getBean("propertiesLoader");
		Properties properties =propertiesLoader.getProperties();
		System.out.println(properties.get("arg1"));
		System.out.println(properties.get("arg2"));
	}
}
